﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace MarioArena.Animation
{
    public abstract class SpriteManager
    {
        protected Texture2D texture;
        public Vector2 position = Vector2.Zero;
        public Color color = Color.White;
        public Vector2 origin = new Vector2(0, 0);
        public float rotation = 0f;
        public float scale = 1.0f;
        public SpriteEffects spriteEffect;
        protected Rectangle[] rectangles;
        protected int frameIndex = 0;

        public SpriteManager(Texture2D texture, int frames)
        {
            this.texture = texture;
            int width = texture.Width / frames;
            rectangles = new Rectangle[frames];
            for (int i = 0; i < frames; i++)
                rectangles[i] = new Rectangle(i * width, 0, width, texture.Height);
        }

        public void Draw(SpriteBatch spriteBatch, Vector2 position)
        {
            spriteBatch.Draw(texture, position, rectangles[frameIndex],
                color, rotation, origin, scale, spriteEffect, 0f);
        }
    }
}
